package com.snow.java.base.junit;

import com.snow.java.base.entity.Student;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @类名称：
 * @类描述：
 * @author: bingHeng
 * @Date 2019.04.07
 * @Version: 1.0
*/
public class MyStream4 {

    public static void main(String[] args) {

        List<Student> studentList = Arrays.asList(
                new Student(1, "张三", 2, 1, 85, Student.Status.BUSY),
                new Student(2, "李四", 2, 2, 60, Student.Status.BUSY),
                new Student(3, "王五", 2, 3, 100, Student.Status.FREE),
                new Student(4, "赵柳", 2, 4, 30, Student.Status.VOCATION),
                new Student(5, "大仙", 2, 5, 25, Student.Status.FREE),
                new Student(6, "小鬼", 2, 6, 74, Student.Status.VOCATION),
                new Student(1, "张三", 2, 1, 85, Student.Status.FREE),
                new Student(100, "张三", 2, 1, 85, Student.Status.BUSY)
        );

        /**
         * 1. 给定一个数字列表，如何返回一个由每个数的平方构成的列表？
         */

        List<Integer> integerList = Arrays.asList(1, 2, 3, 4, 5);
        integerList.stream().map((x) -> x * x).forEach(System.out::println);

        /**
         * 2. 如何使用map和reduce方法计算流中有多少个Student
         */
        Optional<Integer> reduce = studentList.stream().map((e) -> 1).reduce(Integer::sum);
        System.out.println(reduce.get());

    }
}
